//
//  GlobalInfo.swift
//  kz
//
//  Created by Wai Yin Chan on 14/9/2017.
//  Copyright © 2017 Tech_001. All rights reserved.
//

import Foundation
import SwiftyJSON
class GlobalInfo {
    //测试地址
    static var doMainTest = "m2.babababar.com"
    static var resMainTest = "game.manbetlegend.com"
    static var urlTest = "https://javaapi.babababar.com"
    
    static var mainTabBarController: MainTabBarController?
    //添加活动详情页的静态类 防止多次实力化
    static var webViewController: WebViewController?
    //返回判断是不是在活动的详情页进行更新数据
    static var detaileActivityBack: Bool = false
    
    static var listActivityBack:Bool = false
    static var previouslyMaintained: Bool = false
    static var memberInfoData: [String: Any]?
    static var siteInfoData: [String: Any]?
    static var platformInfoData: [[String:Any]]?
    static var recommendGame: [[String:Any]]?// 推荐游戏
    
    static var activitycategoryData: [[String:Any]]?
    static var sponsorUrl : String?
    static var helperInfoData: [[String:Any]]? {
        return self.gameInfoData?["helper"] as? [[String:Any]]
    }
    static var homeHelperList: [[String:Any]]? {
        return self.gameInfoData?["home_helper"] as? [[String:Any]]
    }
    static var helperList: [[String:Any]]?
    static var hallInfoData: [[String:Any]]?
    static var gameInfoData: [String:Any]?
    static var gameMaintainData: [String:String]?
    static var baseInfoData: UserInfoModel?
    static var paymentlist: [[String:Any]]?
    static var bankList:[[String:Any]]?
    static var companyATM:[String:String]?
    static var moneyButton:[String]?
    static var bankImages:[[String:Any]]?
    static var depoistModelList: [[String:Any]]?
    static var  activityIds:[String]?
    static var isWithdrawNative : Bool = false
    //自助客服是否可用
    static var isCsAuto:Bool?
    //广告图
    static var adUrl:String?
    //收藏我们
    static var collectUsUrl:String?
    //客服地址
    static var serviceIurl:String?
    //客服地址2
    static var serviceIurlsec:String?
    static var csDownClient:String?
    //自助客服的地址1
    static var serviceSelfIurl:String?
    //账户的金钱
    static var mtWithBalance:Double?
    //主账户是否使用H5页面
    static var isPlatformMainhtml: Bool?
    //客服弹窗是否显示拨打客服号码
    static var isCallbackPhone:String?
    //是否缓存首页游戏平台图标
    static var isPlatformIconcache:Bool?
    //安全中心url地址
    static var safeUrl:String?
    //桌面app图标类型
    static var appIconType:Int = 0
    static var codeTimeInterval = 120

    // app版本、域名信息
    static var appChannelDic: [String:Any]?
    
    static var mainIpArray: Array<String> {
        return self.getPlistInfo(key: "MainIPArray") as! Array
    }
    
    static var mainIsTest : Bool {
        return self.getPlistInfo(key: "isTest") as! Bool
    }
    
    static var getGameJson : String{
//        if isTest{
//            return "/game.json"
//        }else{
        
//            return "/game_new.json"
        return "/config.json"
        
//        }
    }
    
    static var CircuitContent: String {
        return self.getPlistInfo(key: "CircuitContent") as! String
    }
    
    static var apiDomain: String {
        if(isTest){
            return self.doMainTest
        }
        return self.getPlistInfo(key: "api_Domain") as! String
    }
    
    static var defaultCSUrl: String{
        return self.getPlistInfo(key: "default_CS_URL") as! String
    }
    
    static var defaultCS_Sec_Url: String{
        return self.getPlistInfo(key: "default_CS_Sec_URL") as! String
    }
    static var resDomain: String {
        if(isTest){
            return self.resMainTest
        }
        return self.getPlistInfo(key: "res_Domain") as! String
    }
    
    static var useWebReg: Bool {
        return self.getPlistInfo(key: "use_Web_REG") as! Bool
    }
    
    static var versionFile: String {
        return self.getPlistInfo(key: "versionFile") as! String
    }
    
    static var versionFileManually: String {
        return self.getPlistInfo(key: "versionFileManually") as! String
    }
    
    static func getPlistInfo(key: String) -> Any?{
        let path = Bundle.main.path(forResource: "Info", ofType:"plist")
        let dict = NSDictionary(contentsOfFile:path!)
        
        return dict?.value(forKey: key)
    }
    // 系统维护
    static func isMaintain() -> Bool{
        let isMaintain = GlobalInfo.gameInfoData?["is_maintain"]
        if let maintain = isMaintain as? Bool, maintain == true {
            previouslyMaintained = true
            return true
        }
        
        previouslyMaintained = false
        return false
    }
    
    static func getDefaultJson() -> Data {
        if let content = UserDefaults.standard.data(forKey: DefaultKey.DEFAULT_GAME_JSON) {
            print("Loaded cached game.json")
            return content
        }
        
        do{
            let path = Bundle.main.path(forResource: "DefaultGameJson", ofType:"txt")
            let content = try String(contentsOfFile: path!)
        
            print("Loaded local game.json")
            return content.data(using: .utf8)!
        }catch{
            return "".data(using: .utf8)!
        }
    }
    // 渠道编号 - 参数：tag "d0"- 官方包，"d1 - d120",对应另外的的120个包
    static var tagFlag: String {
        return self.getPlistInfo(key: "tag_flag") as! String
    }
    
}
